package com.yyq.sos.tag;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.yyq.sos.util.PermissionsUtil;

public class ConditionTag extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3255090809139434911L;
	private String name;
	private String rescode;
	private String optcode;
	private boolean hasPermission = false;
	

	@Override
	public int doStartTag() throws JspException {

		HttpSession session = this.pageContext.getSession();
		if(rescode!=null && optcode==null){
			hasPermission = PermissionsUtil.checkPermissionByCode(session, rescode);
		}else if(rescode != null && optcode != null){
			hasPermission = PermissionsUtil.checkPermissionByCode(session, rescode,optcode);
		}else{
			hasPermission = false;
		}
		if(hasPermission){
			return EVAL_BODY_INCLUDE;
		}else{
			return SKIP_BODY;
		}
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRescode() {
		return rescode;
	}
	public void setRescode(String rescode) {
		this.rescode = rescode;
	}
	public String getOptcode() {
		return optcode;
	}
	public void setOptcode(String optcode) {
		this.optcode = optcode;
	}
}
